Skip to content

Fix proxy panic when balancer has no targets#2977

Merged
aldas merged 1 commit into
labstack:masterfrom
shblue21:fix/proxy-no-target-panic
May 21, 2026
Merged

Fix proxy panic when balancer has no targets#2977
aldas merged 1 commit into
labstack:masterfrom
shblue21:fix/proxy-no-target-panic

Conversation

@shblue21
Copy link
Copy Markdown
Contributor

Fixes #2976

This fixes a panic when a proxy balancer returns no target.

Built-in balancers can return nil when the target list is empty, for example after RemoveTarget removes the last target. ProxyWithConfig now returns 502 Bad Gateway through the configured error handler instead of passing the nil target to proxyHTTP or proxyRaw.

I also added a test for a custom balancer returning a target with a nil URL.

Tests pass with go test ./... -count=1.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.17%. Comparing base (01b45be) to head (7b5690a).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2977      +/-   ##
==========================================
- Coverage   93.17%   93.17%   -0.01%     
==========================================
  Files          43       43              
  Lines        4501     4499       -2     
==========================================
- Hits         4194     4192       -2     
  Misses        189      189              
  Partials      118      118              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@aldas aldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aldas aldas merged commit 98d99d5 into labstack:master May 21, 2026
10 checks passed
@aldas
Copy link
Copy Markdown
Contributor

aldas commented May 21, 2026

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy middleware can panic when the balancer has no targets

2 participants